import 'dart:convert';

import 'package:dio/dio.dart';
import 'package:wuxu_flutter_lianxi/dao/UserDao.dart';

class TokenInterceptor extends InterceptorsWrapper {

  @override
  onRequest(RequestOptions options, RequestInterceptorHandler handler) async {
    var token = UserDao.userInfo?.token;
    if (token != null) {
      options.headers["Authorization"] = "Bearer $token";
    }
    super.onRequest(options, handler);
  }

  @override
  onResponse(Response response, ResponseInterceptorHandler handler) async {
    // try {
    //   var responseJson = response.data;
    //   if (response.statusCode == 200 &&
    //       responseJson["result"]?["token"] != null) {
    //     await LocalStorage.save(Config.USER_INFO, json.encode( responseJson["result"]));
    //   }
    // } catch (e) {
    //   print(e);
    // }
    return super.onResponse(response, handler);
  }
}
